package com.iotteam.androidbase.commen.views.charts;

import android.graphics.Canvas;
import android.graphics.Paint;

import com.iotteam.androidbase.commen.views.charts.line.DefaultMapper;
import com.iotteam.androidbase.commen.views.charts.line.ILocationMapper;
import com.iotteam.androidbase.commen.views.charts.line.Line;

/**
 * Created by vonchenchen on 16/08/2017.
 */

public class LineRenderer extends AbsRenderer {

    private Line mLine;
    private Axis mXAxis;
    private Axis mYAxis;

    public Paint mLinePaint;

    private ILocationMapper mMapper = null;

    public LineRenderer(Line line, Axis xAxis, Axis yAxis){
        mLine = line;
        mXAxis = xAxis;
        mYAxis = yAxis;
        mMapper = new DefaultMapper();

        line.setRenderer(this);
        mLinePaint = line.getPaint();
    }

    public void setLocationMaper(ILocationMapper maper){
        mMapper = maper;
    }

    @Override
    public void render(Canvas canvas) {

        int size = mLine.getDataList().size();

        Point startPoint = mMapper.map(mLine.getDataList().get(0), mXAxis, mYAxis);
        Point endPoint;

        for(int i=1; i<size; i++){
            endPoint = mMapper.map(mLine.getDataList().get(i), mXAxis, mYAxis);
            drawLine(canvas, startPoint, endPoint, mLinePaint);
            startPoint = endPoint;
        }
    }
}
